<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let object = {
            name: "奉先",
            age: 35,
            sex: "男",
            [Symbol.for("name")]: "人类",
            [Symbol.for("dimension")]: "三次元",
            // 采用return {next()} 函数的方式，不需要*
            [Symbol.iterator]() {
                let keys = Object.keys(this);
                let index = 0;
                return {
                    // 这里使用箭头函数
                    next: () => {
                        if (index >= keys.length) {
                            // done: true，表示结束遍历
                            return {
                                done: true,
                                value: undefined,
                            }
                        } else {
                            return {
                                done: false,
                                value: this[keys[index ++]]
                            }
                        }  
                    }
                }
            }
        }

        // Object.keys()：只能返回普通属性（可枚举属性）
        let keys = Object.keys(object);
        console.log(keys); // [ "name", "age", "sex" ]

        // 只能返回普通属性（含不可枚举属性）
        keys = Object.getOwnPropertyNames(object);
        console.log(keys); // [ "name", "age", "sex" ]

        keys = Object.getOwnPropertySymbols(object);
        console.log(keys);
        for (let v of keys) {
            console.log(object[v]);
        }

        console.log([...object]);
    </script>
</body>
</html>